// pages/particulars/particulars.js
const config = require("../../utils/config.js")
const req = require("../../utils/request.js")
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    nameList:[],
    imgList:[],
    retail_price: [],
    idList:[]
  },
  getData:function(){
    var that = this
    var idx = app.globalData.categoryListId
    var index = app.globalData.index
    var id = idx[index]
    console.log(id)
    var nameList = that.data.nameList
    var imgList = that.data.imgList
    var retail_price = that.data.retail_price
    var idList = that.data.idList
    req.request(config.goods, "GET", {categoryId: id},function(res){
      console.log(res)
      for (var i = 0; i < res.data.data.goodsList.length; i++) {
          nameList[i] = res.data.data.goodsList[i].name
          imgList[i] = res.data.data.goodsList[i].list_pic_url
          retail_price[i] = res.data.data.goodsList[i].retail_price
          idList[i] = res.data.data.goodsList[i].id
        }
        that.setData({
          nameList: nameList,
          imgList: imgList,
          retail_price: retail_price,
          idList : idList
        })
        app.globalData.id = idList
    })
  },
  xiangqing:function(res){
      console.log(res)
      app.globalData.idx = res.currentTarget.dataset.index
      wx.navigateTo({
        url: '../details/details'
      })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getData()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})